<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        function copyUrl2() {
            var Url2 = document.getElementById("biao1");
            Url2.select(); // 选择对象 
            document.execCommand("Copy"); // 执行浏览器复制命令 
            alert("已复制好，可贴粘。");
        }
        // window.onload = function () {
        //     copyUrl2()
        // }


        $(document).ready(function () {
           
            copyUrl2()
            
        }); 
    </script>
    <textarea cols="20" rows="10" id="biao1">用户定义的代码区域</textarea>
    <input type="button" onClick="copyUrl2()" value="点击复制代码" />
</body>

</html>